package com.cuckoo.mall.thus.menuaccount.language;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bgn.baseframe.base.BaseActivity;
import com.bgn.baseframe.utils.LanguageUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.LanguageItem;


import java.util.ArrayList;
import java.util.List;

/** * 作者：wl on 2018/4/ * 邮箱：wanglun@stosz.com */

@Route(path = "/mall/languageActivity", group = "mall")
public class LanguageActivity extends BaseActivity {

    private RecyclerView rv_list;
    private LanguageListAdapter adapter;
    private List<LanguageItem> languageItems = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_language_setting);
        initView();
        languageItems.add(new LanguageItem("简体中文", LanguageUtil.CHINESE_SIMPLIFIED, R.mipmap.cn));
        languageItems.add(new LanguageItem("繁體（香港）", LanguageUtil.CHINESE_HK, R.mipmap.cn));
        languageItems.add(new LanguageItem("繁體（台灣）", LanguageUtil.CHINESE_TW, R.mipmap.cn));
        languageItems.add(new LanguageItem("English", LanguageUtil.ENGLISH, R.mipmap.us));

        adapter = new LanguageListAdapter(R.layout.list_item_language, languageItems);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
                adapter.setSelectPosition(position);
                adapter.notifyDataSetChanged();
                savestaAndSwichLanguage(languageItems.get(position).getCode());
            }
        });
        rv_list.setAdapter(adapter);
        rv_list.setLayoutManager(new LinearLayoutManager(this));

    }

    public void initView() {
        rv_list = findViewById(R.id.rv_list);
        getTitleBar().setTitle(getString(R.string.ac_language_title));

    }

    private void savestaAndSwichLanguage(String code) {
        LanguageUtil.savedLanguage2Country(code);
        ARouter.getInstance().build("/mall/mainActivity").withString("action", "lang")
                .navigation();
    }

}
